/*
 * endpoint.c
 *
 *  Created on: Feb 13, 2012
 *      Author: jiabin
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

enum MODE {CLIENT, AGENT};
int client_main(int portno, const char *ip);
int agent_main(int portno, int index);

int main(int argc, char *argv[])
{
	int opt, port = -1, index;
	enum MODE mode;
	char *ip;

	while ((opt = getopt(argc, argv, "l:h:p:")) != -1)
	{
		switch (opt)
		{
		case 'l':
			mode = AGENT;
			index = atoi(optarg);
			break;
		case 'h':
			ip = optarg;
			mode = CLIENT;
			break;
		case 'p':
			port = atoi(optarg);
			break;
		default:
            fprintf(stderr, "Usage: %s [-p portno] [-l|-h ip]\n",
                    argv[0]);
            exit(EXIT_FAILURE);
		}
	}

	if (mode == CLIENT)
		client_main(port, ip);
	else
	{
		agent_main(port, index);
	}

	return 0;
}
